import { http } from "@/utils/http";
import type { ResultProps } from "@/api/user";

export interface TaskVersionModel {
  /**
   * 要拷贝的版本ID
   */
  copyVersion: string;
  /**
   * 版本名称
   */
  name?: string;
  /**
   * 版本描述
   */
  note?: string;
  /**
   * 上架状态：0->下架；1->上架
   */
  publishStatus?: number;

  [property: string]: any;
}

export const taskVersionAdd = (data?: TaskVersionModel) => {
  return http.requestJson<ResultProps<null>>("post", "/taskVersion/add", {
    data
  });
};

export const taskVersionUpd = (
  data?: Omit<TaskVersionModel, "copyVersion">
) => {
  return http.requestJson<ResultProps<null>>("post", "/taskVersion/upd", {
    data
  });
};

export interface TaskVersionProp {
  id: number;
  accountId: number;
  businessId: number;
  name: string;
  note: string;
  deleteStatus: number;
  publishStatus: number;
  publishTime: null;
  updateTime: Date;
  createTime: Date;
}

export const taskVersionGetList = (data?: object) => {
  return http.requestJson<ResultProps<TaskVersionProp[]>>(
    "post",
    "/taskVersion/getList",
    {
      data
    }
  );
};

export const taskVersionDel = (data?: object) => {
  return http.requestJson<ResultProps<null>>("post", "/taskVersion/del", {
    data
  });
};

export const taskVersionPublish = (data?: object) => {
  return http.requestJson<ResultProps<null>>("post", "taskVersion/publish", {
    data
  });
};

export const taskVersionRelease = (data?: object) => {
  return http.requestJson<ResultProps<null>>("post", "taskVersion/release", {
    data
  });
};

export interface TaskVersionReleaseProp {
  id: number;
  accountId: number;
  businessId: number;
  moduleKey: string;
  moduleId: string;
  groupId: null;
  storeId: null;
  deviceId: string;
  note: string;
  releaseTime: Date;
}

export const taskVersionReleaseList = (data?: object) => {
  return http.requestJson<ResultProps<TaskVersionReleaseProp[]>>(
    "post",
    "/taskVersion/getReleaseList",
    {
      data
    }
  );
};

export interface TaskAddModel {
  id?: number;
  /**
   * 循环类型 1->每天 2->每周 3->每月
   */
  loopType?: number;
  /**
   * 任务名称
   */
  name?: string;
  /**
   * 任务详情描述
   */
  note?: string;
  /**
   * 开启状态：0->已关闭；1->已开启
   */
  openStatus?: number;
  /**
   * "00:00"
   */
  reminderDay?: string;
  /**
   * 提醒时间集合（时分）
   */
  reminderHour?: string;
  /**
   * 提醒时间集合（月）
   */
  reminderMonth?: string;
  /**
   * 提醒时间集合（周）
   */
  reminderWeek?: string;
  /**
   * 提醒类型 1->单次提醒  2->重复提醒
   */
  reminderType: number;
  /**
   * 单次提醒的时间点，格式为：2024-12-04 04:29:16
   */
  singleReminderTime?: string;
  /**
   * 分类ID
   */
  typeId: number;
  /**
   * 版本ID
   */
  versionId: number;

  [property: string]: any;
}

export const taskAdd = (data?: TaskAddModel) => {
  return http.requestJson<ResultProps<null>>("post", "/task/add", {
    data
  });
};

export const taskUpd = (data?: TaskAddModel) => {
  return http.requestJson<ResultProps<null>>("post", "/task/upd", {
    data
  });
};

export interface TaskListProp {
  id: number;
  accountId: number;
  businessId: number;
  name: string;
  note: string;
  versionId: number;
  typeId: number;
  reminderType: number;
  singleReminderTime: string;
  loopType: number | null;
  reminderHour: null | string;
  deleteStatus: number;
  openStatus: number;
  updateTime: Date;
  createTime: Date;
  reminderWeek: null | string;
  reminderMonth: null | string;
}

export const taskGetList = (data?: object) => {
  return http.requestJson<ResultProps<TaskListProp[]>>(
    "post",
    "/task/getList",
    {
      data
    }
  );
};

export const taskDel = (data?: { ids: number[] }) => {
  return http.requestJson<ResultProps<null>>("post", "/task/del", {
    data
  });
};

export interface TaskTypeAddModel {
  id?: number;
  /**
   * 任务类型名称
   */
  name?: string;
  /**
   * 任务类型描述
   */
  note?: string;
  subId?: number | string;

  [property: string]: any;
}

export const taskTypeAdd = (data?: TaskTypeAddModel) => {
  return http.requestJson<ResultProps<null>>("post", "/taskType/add", {
    data
  });
};

export const taskTypeUpd = (data?: TaskTypeAddModel) => {
  return http.requestJson<ResultProps<null>>("post", "/taskType/upd", {
    data
  });
};

export interface TaskTypeListProp {
  /**
   * 账号ID
   */
  accountId?: number;
  /**
   * 商家ID
   */
  businessId?: number;
  /**
   * 创建时间
   */
  createTime: string;
  /**
   * 删除状态：0->未删除；1->已删除
   */
  deleteStatus?: number;
  /**
   * 自增分类ID
   */
  id: number;
  /**
   * 任务类型名称
   */
  name?: string;
  /**
   * 任务类型描述
   */
  note?: string;
  subId?: string | number;
  /**
   * 更新时间
   */
  updateTime: string;

  [property: string]: any;
}

export const taskTypeGetList = (data?: object) => {
  return http.requestJson<ResultProps<TaskTypeListProp[]>>(
    "post",
    "/taskType/getList",
    {
      data
    }
  );
};

export const taskTypeDel = (data?: { ids: string[] }) => {
  return http.requestJson<ResultProps<null>>("post", "/taskType/del", {
    data
  });
};
